package annotation;

import constant.Common;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;

/**
 * 处理方法的参数，替换指定字符串
 *
 * @author zhanglinfeng
 * @date create in 2022/8/31 11:17
 */
@Aspect
public class ReplaceAspect implements Ordered {

    @Override
    public int getOrder() {
        return 2;
    }

    @Pointcut("@annotation(annotation.Replace)")
    public void pointcut() {
    }

    @Around(value = "pointcut()")
    public Object doAspect(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        for (int i = 0; i < args.length; i++) {
            String val = String.valueOf(args[i]);
            //需要替换的字符串
            if (Common.BLANK.equals(val)) {
                args[i] = null;
            }
        }
        return joinPoint.proceed(args);
    }

}
